Skip to content

New implementation of QIR codegen.#2542

Merged
schweitzpgi merged 6 commits intoNVIDIA:mainfrom
schweitzpgi:ch-reorg.qir.codegen
Feb 3, 2025
Merged

New implementation of QIR codegen.#2542
schweitzpgi merged 6 commits intoNVIDIA:mainfrom
schweitzpgi:ch-reorg.qir.codegen

Conversation

@schweitzpgi
Copy link
Collaborator

@schweitzpgi schweitzpgi commented Jan 24, 2025

The QIR codegen is one of the oldest pieces of the project and really shows its age at this point. It was written before much of the rest of the core was implemented or even designed.

These changes replace the existing QIR codegen for the C++ compiler. Unfortunately, there are a number of semantics violations from Python that need to be fixed before it can be switched over. Therefore, this PR leaves Python intact and using the old codegen passes.

The purpose of these changes is two-fold.

  1. Instead of converting all of the IR to the LLVM-IR dialect at the same time as converting to QIR, these two steps are bifurcated. This allows us to convert the quake dialect to other higher level operations first and before LLVM-IR dialect is introduced. This will be beneficial in short order...
  2. Instead of piecemealing different flavors of QIR in completely ad hoc spaghetti plate passes, the flavor of QIR is specified as a mixin modifier class for a singular set of steps to convert to any flavor of QIR. This does mean that one will no longer be able to convert to the LLVM-IR dialect with QIR calls and then change their mind from chocolate QIR to strawberry QIR much later.

@schweitzpgi schweitzpgi marked this pull request as draft January 24, 2025 22:21
github-actions bot pushed a commit that referenced this pull request Jan 24, 2025
github-actions bot pushed a commit that referenced this pull request Jan 27, 2025
github-actions bot pushed a commit that referenced this pull request Jan 27, 2025
github-actions bot pushed a commit that referenced this pull request Jan 27, 2025
github-actions bot pushed a commit that referenced this pull request Jan 27, 2025
github-actions bot pushed a commit that referenced this pull request Jan 27, 2025
github-actions bot pushed a commit that referenced this pull request Jan 28, 2025
github-actions bot pushed a commit that referenced this pull request Jan 28, 2025
github-actions bot pushed a commit that referenced this pull request Jan 28, 2025
github-actions bot pushed a commit that referenced this pull request Jan 28, 2025
github-actions bot pushed a commit that referenced this pull request Jan 29, 2025
@github-actions
Copy link

CUDA Quantum Docs Bot: A preview of the documentation can be found here.

github-actions bot pushed a commit that referenced this pull request Jan 29, 2025
@github-actions
Copy link

CUDA Quantum Docs Bot: A preview of the documentation can be found here.

github-actions bot pushed a commit that referenced this pull request Jan 29, 2025
@github-actions
Copy link

CUDA Quantum Docs Bot: A preview of the documentation can be found here.

github-actions bot pushed a commit that referenced this pull request Jan 29, 2025
@schweitzpgi schweitzpgi marked this pull request as ready for review January 29, 2025 16:07
@github-actions
Copy link

CUDA Quantum Docs Bot: A preview of the documentation can be found here.

github-actions bot pushed a commit that referenced this pull request Jan 29, 2025
@NVIDIA NVIDIA deleted a comment from github-actions bot Jan 29, 2025
@NVIDIA NVIDIA deleted a comment from github-actions bot Jan 29, 2025
@NVIDIA NVIDIA deleted a comment from github-actions bot Jan 29, 2025
@NVIDIA NVIDIA deleted a comment from github-actions bot Jan 29, 2025
@NVIDIA NVIDIA deleted a comment from github-actions bot Jan 29, 2025
@NVIDIA NVIDIA deleted a comment from github-actions bot Jan 29, 2025
@NVIDIA NVIDIA deleted a comment from github-actions bot Jan 29, 2025
@NVIDIA NVIDIA deleted a comment from github-actions bot Jan 29, 2025
@NVIDIA NVIDIA deleted a comment from github-actions bot Jan 29, 2025
@github-actions
Copy link

CUDA Quantum Docs Bot: A preview of the documentation can be found here.

github-actions bot pushed a commit that referenced this pull request Jan 29, 2025
@github-actions
Copy link

CUDA Quantum Docs Bot: A preview of the documentation can be found here.

shows its age at this point. It was written before much of the rest
of the core was implemented or even designed.

These changes replace the existing QIR codegen for the C++ compiler.
Unfortunately, there are a number of semantics violations from Python
that need to be fixed before it can be switched over. Therefore, this
PR leaves Python intact and using the old codegen passes.

The purpose of these changes is two-fold.

 1. Instead of converting all of the IR to the LLVM-IR dialect at
    the same time as converting to QIR, these two steps are bifurcated.
    This allows us to convert the quake dialect to other higher level
    operations first and before LLVM-IR dialect is introduced. This
    will be beneficial in short order...
 2. Instead of piecemealing different flavors of QIR in completely ad
    hoc spaghetti plate passes, the flavor of QIR is specified as a
    mixin modifier class for a singular set of steps to convert to any
    flavor of QIR. This does mean that one will no longer be able to
    convert to the LLVM-IR dialect with QIR calls and then change their
    mind from chocolate QIR to strawberry QIR much later.

Notes:
 - Remove the option to disable the qir profile preparation pass.
   This pass is not optional. The IR will be translated to an
   invalid state if the required function declarations are not
   created at all.
 - Make it clear that AggressiveEarlyInlining is a pipeline. Refactor
   the registration functions so that we're not block-copying things
   between the core and python (which was dropping things on the floor
   already).
 - Add a new pass, convert to QIR API.
   This pass will replace the cascade of passes to convert to full QIR and
   then convert some more to base profile or adaptive profile.
 - Refactor QIRFunctionNames.h.
 - Add a raft of declarations to the intrinsics table. This will
   dramatically reduce the amount of code in codegen and make
   maintenance much easier.
 - Add the analysis and prep pass.
 - Improve pipeline locality and performance.
 - Use the new code in the default code gen path for C++.
 - Workarounds for issue NVIDIA#2541 and issue NVIDIA#2539. Keep the old codegen for
   python. Too many bugs.
 - Update tests. Fix bugs in mock servers. Have python kernel builder add the
   cudaq-kernel attribute. (See issue 2541.)

Signed-off-by: Eric Schweitz <eschweitz@nvidia.com>
Signed-off-by: Eric Schweitz <eschweitz@nvidia.com>
Signed-off-by: Eric Schweitz <eschweitz@nvidia.com>
Signed-off-by: Eric Schweitz <eschweitz@nvidia.com>
Signed-off-by: Eric Schweitz <eschweitz@nvidia.com>
@schweitzpgi schweitzpgi enabled auto-merge (squash) February 3, 2025 16:19
github-actions bot pushed a commit that referenced this pull request Feb 3, 2025
@github-actions
Copy link

github-actions bot commented Feb 3, 2025

CUDA Quantum Docs Bot: A preview of the documentation can be found here.

Copy link
Collaborator

@khalatepradnya khalatepradnya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏🏼 for the humungous effort!

I reviewed the changes under python and updates to the tests. I didn't closely review the new codegen pass.

@schweitzpgi schweitzpgi merged commit a53c378 into NVIDIA:main Feb 3, 2025
211 checks passed
github-actions bot pushed a commit that referenced this pull request Feb 3, 2025
@github-actions
Copy link

github-actions bot commented Feb 3, 2025

CUDA Quantum Docs Bot: A preview of the documentation can be found here.

github-actions bot pushed a commit that referenced this pull request Feb 3, 2025
@schweitzpgi schweitzpgi deleted the ch-reorg.qir.codegen branch February 3, 2025 22:15
@bettinaheim bettinaheim added the release notes Changes need to be captured in the release notes label Mar 12, 2025
@bettinaheim bettinaheim added this to the release 0.10.0 milestone Mar 12, 2025
@bettinaheim bettinaheim changed the title [core] This is a new implementation of QIR codegen. New implementation of QIR codegen. Mar 12, 2025
annagrin pushed a commit to annagrin/cuda-quantum that referenced this pull request Jun 17, 2025
* The QIR codegen is one of the oldest pieces of the project and really
shows its age at this point. It was written before much of the rest
of the core was implemented or even designed.

These changes replace the existing QIR codegen for the C++ compiler.
Unfortunately, there are a number of semantics violations from Python
that need to be fixed before it can be switched over. Therefore, this
PR leaves Python intact and using the old codegen passes.

The purpose of these changes is two-fold.

 1. Instead of converting all of the IR to the LLVM-IR dialect at
    the same time as converting to QIR, these two steps are bifurcated.
    This allows us to convert the quake dialect to other higher level
    operations first and before LLVM-IR dialect is introduced. This
    will be beneficial in short order...
 2. Instead of piecemealing different flavors of QIR in completely ad
    hoc spaghetti plate passes, the flavor of QIR is specified as a
    mixin modifier class for a singular set of steps to convert to any
    flavor of QIR. This does mean that one will no longer be able to
    convert to the LLVM-IR dialect with QIR calls and then change their
    mind from chocolate QIR to strawberry QIR much later.

Notes:
 - Remove the option to disable the qir profile preparation pass.
   This pass is not optional. The IR will be translated to an
   invalid state if the required function declarations are not
   created at all.
 - Make it clear that AggressiveEarlyInlining is a pipeline. Refactor
   the registration functions so that we're not block-copying things
   between the core and python (which was dropping things on the floor
   already).
 - Add a new pass, convert to QIR API.
   This pass will replace the cascade of passes to convert to full QIR and
   then convert some more to base profile or adaptive profile.
 - Refactor QIRFunctionNames.h.
 - Add a raft of declarations to the intrinsics table. This will
   dramatically reduce the amount of code in codegen and make
   maintenance much easier.
 - Add the analysis and prep pass.
 - Improve pipeline locality and performance.
 - Use the new code in the default code gen path for C++.
 - Workarounds for issue NVIDIA#2541 and issue NVIDIA#2539. Keep the old codegen for
   python. Too many bugs.
 - Update tests. Fix bugs in mock servers. Have python kernel builder add the
   cudaq-kernel attribute. (See issue 2541.)

Signed-off-by: Eric Schweitz <eschweitz@nvidia.com>

---------

Signed-off-by: Eric Schweitz <eschweitz@nvidia.com>
Signed-off-by: Anna Gringauze <agringauze@nvidia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release notes Changes need to be captured in the release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants